package com.bvr;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Vector;

import org.json.JSONException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class EarningActivty extends Activity {

	public static EarningObject _earning;

	/* UI Controls Start */
	TextView lblTitle;
	TextView lblLocation;
	TextView lblFrom;
	TextView lblDate;
	TextView lblStatus;
	TextView lblRate;

	TextView lblEmail;
	TextView lblOwnerName;
	TextView lblComments;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.earning);
		setUI();
	}

	private void setUI() {
		lblTitle = (TextView) findViewById(R.id.earningPropertyTitleDetail);
		lblLocation = (TextView) findViewById(R.id.earningPropertyLocationDetail);
		lblFrom = (TextView) findViewById(R.id.earningTransTypeDetail);
		lblDate = (TextView) findViewById(R.id.earningTransDateDetail);
		lblStatus = (TextView) findViewById(R.id.earningStatusDetail);
		lblRate = (TextView) findViewById(R.id.earningOwnerAmountDetail);

		lblEmail = (TextView) findViewById(R.id.earningOwnerEmailDetail);
		lblOwnerName = (TextView) findViewById(R.id.earningOwnerNameDetail);
		lblComments = (TextView) findViewById(R.id.earningCommentsDetail);

		if (lblTitle != null) {
			lblTitle.setText(_earning.getPropertyTitle());
		}
		if (lblLocation != null) {
			lblLocation.setText(_earning.getPropertyLocation());
		}
		if (lblFrom != null) {
			lblFrom.setText(_earning.getTransType());
		}
		if (lblDate != null) {
			lblDate.setText(_earning.getTransDate());
		}
		if (lblStatus != null) {
			lblStatus.setText(_earning.getStatus());
			if (_earning.getStatus().toString().equalsIgnoreCase("pending")) {
				lblStatus.setTextColor(Color.RED);
			} else {
				lblStatus.setTextColor(Color.parseColor("#43A51B"));
			}
		}
		if (lblRate != null) {
			lblRate.setText("$" + _earning.getOwnerAmount());
		}

		if (lblEmail != null) {
			lblEmail.setText(_earning.getOwnerEmail());
		}
		if (lblOwnerName != null) {
			lblOwnerName.setText(_earning.getOwnerName());
		}
		
		String strComments = _earning.getSalesComment().toString();
		
		
		if (lblComments != null) {
			if (!strComments.equalsIgnoreCase("") &&!strComments.equalsIgnoreCase("anyType{}") && strComments != null && strComments.length() > 0) {
				lblComments.setText(_earning.getSalesComment());
			}
			else
			{
				lblComments.setText("");
			}
		}
	}

	private String[] splitString(String original, String separator) {

		Vector nodes = new Vector();

		// Parse nodes into vector
		int index = original.indexOf(separator);

		while (index >= 0) {
			nodes.addElement(original.substring(0, index));

			original = original.substring(index + separator.length());

			index = original.indexOf(separator);

		}
		// Get the last node
		nodes.addElement(original);

		// Create split string array
		String[] result = new String[nodes.size()];

		if (nodes.size() > 0) {

			for (int loop = 0; loop < nodes.size(); loop++)

			{
				result[loop] = (String) nodes.elementAt(loop);

				// System.out.println(result[loop]);

			}

		}
		return result;
	}

	public void debugDisplay(String s) {
		System.out.println(s);
	}
}
